package com.lct.simpleforecast.ui.activity

import com.lct.simpleforecast.R
import com.lct.simpleforecast.extensions.loadImgByGlide
import com.lct.simpleforecast.extensions.setTextWithFormatArgs
import com.lct.simpleforecast.ui.activity.base.BaseActivity
import kotlinx.android.synthetic.main.activity_detail.*

/**
 * 显示天气详情：图标，白天天气，夜间天气，最高温度，最低温度，风向，风力
 */
class DetailActivity : BaseActivity() {
    //启动该页面需要的参数
    companion object {
        const val LOCATION = "DetailActivity:location"
        const val DATE = "DetailActivity:date"
        const val ICON = "DetailActivity:icon"
        const val DAY_DES = "DetailActivity:dayDes"
        const val NIGHT_DES = "DetailActivity:nightDes"
        const val TEMP_MAX = "DetailActivity:tempMax"
        const val TEMP_MIN = "DetailActivity:tempMin"
        const val WIND_DIRECTION = "DetailActivity:windDirection"
        const val WIND_LEVEL = "DetailActivity:windLevel"
    }

    /**
     * 设置activity的布局
     */
    override fun setLayoutResId(): Int {
        return R.layout.activity_detail
    }

    /**
     * 初始化数据
     */
    override fun initData() {
        //toolbar
        toolbar?.title = intent.getStringExtra(LOCATION)
        toolbar?.subtitle = intent.getStringExtra(DATE)
        enableHomeAsUp()
        //天气数据
        ivIcon.loadImgByGlide(intent.getStringExtra(ICON))
        tvDesDay.setTextWithFormatArgs(R.string.weather_des_day, intent.getStringExtra(DAY_DES))
        tvDesNight.setTextWithFormatArgs(R.string.weather_des_night,
                intent.getStringExtra(NIGHT_DES))
        tvTempMax.setTextWithFormatArgs(R.string.weather_temp_max, intent.getStringExtra(TEMP_MAX))
        tvTempMin.setTextWithFormatArgs(R.string.weather_temp_min, intent.getStringExtra(TEMP_MIN))
        tvWindDirection.setTextWithFormatArgs(R.string.weather_wind_direction,
                intent.getStringExtra(WIND_DIRECTION))
        tvWindLevel.setTextWithFormatArgs(R.string.weather_wind_level,
                intent.getStringExtra(WIND_LEVEL))
    }
}
